import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store =new Vuex.Store({
    state:{
        token:"",  //用户凭据
        res:{}   //用户数据
    },
    getters:{},
    mutation:{
        setToken(state,token){
            state.token=token
        }
    },
    actions: {
        // 获取token
        async fetchToken(store){
            const data={ password:'345678',
            phoneNumber:'18812345678',
            platform:'1',}
         //发起网络请求
        const res=  await uni.$u.post('/xssh/userRegister/passwordLogin', { password:'345678',
        phoneNumber:'18812345678',
        platform:'1',})
        console.log(res)
           const {token}=res.data
           store.commit("setToken",token)
        }
    }
})
export default store